# -*- coding: utf-8 -*-
"""
Created on Wed Jul 31 13:03:39 2013

@author: Jeanhwea
"""
from urllib import urlopen
from time import time, localtime, strftime
url = 'http://www.icbc.com.cn/FinanceMarket/gold/Default.aspx'
sub = 'ctl00_Content_Boby_AccountGold1_Label_mrj1'
sleepTime = 10
soldprice = 274.41
quantity = 42

def main():
    res = urlopen(url)
    html = res.read()
    index = html.find(sub)
    start = index + len(sub) + 17
    price = float(html[start:start+6])
    currentTime = strftime('%H:%M:%S (%Y-%m-%d)',localtime(time()))
    net =  (price - soldprice)*quantity
    print("%.2f at %s, %.2f" %(price, currentTime, net))
    
if __name__ == '__main__':
    main()
